import { http } from "@/utils/request";
import type {
  EmailCodeParams,
  ResetPasswordByEmailParams,
} from "@/types/forget";

/**
 * 发送邮箱验证码
 * @param data - 包含邮箱和验证码类型的参数
 * @returns 返回API响应结果
 */
export const getEmailCodeAPI = (data: EmailCodeParams) => {
  return http({
    method: "POST",
    url: "/api/v1/email/sendEmail",
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data,
  });
};

/**
 * 通过邮箱重置密码
 * @param data - 包含邮箱、新密码和验证码的参数
 * @returns 返回API响应结果
 */
export const resetPasswordByEmailAPI = (data: ResetPasswordByEmailParams) => {
  return http<string>({
    method: "POST",
    url: "/api/v1/users/resetPasswordByEmail",
    header: {
      "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
    },
    data,
  });
};
